package operation;

import book.bookList;

import javax.crypto.spec.PSource;
import java.util.Scanner;

/**
 * @Author @fiber-cloud
 * @Date 2025/7/13 15:33
 * 归还图书
 */
public class ReturnOperation implements IOperation{

    @Override
    public void work(bookList booklist) {
        System.out.println("归还图书");

        System.out.println("请输入你要归还图书的书名");
        Scanner sc = new Scanner(System.in);
        String bookName = sc.nextLine();

        for (int i = 0; i < booklist.getCount(); i++) {
            if (bookName.equals(booklist.getBooks(i).getName())){
                //书架上存在的书被借出了
                booklist.getBooks(i).setBorrowing(false);
                System.out.println("成功归还"+ "《"+ bookName + "》");
                return;
            }else {
                //该书存在，但并未被借出
                System.out.println("《"+ bookName + "》"+"该书并未被借出，请核对书名是否正确");
            }
        }
        System.out.println("未找到"+ "《"+ bookName + "》");
    }

}
